<!DOCTYPE html>
<html lang="en">
<?php include "../proses/konek.php";
session_start();
if(!isset($_SESSION['username']))
   {   
  ?><script language="javascript">alert('anda blm login');
document.location='../'</script><?php 
}
else
{
$username = $_SESSION['username'];
$status = $_SESSION['status'];
}

if(!isset($_GET['id']))
   {   
   ?><script language="javascript">alert('DATA TIDAK DITEMUKAN');
document.location='../page/listpost.php'</script><?php
 }
else
{
$id = $_GET['id'];
}
$sql=mysql_query("select * from posting where idpost='$id'");
$cek=mysql_fetch_assoc($sql);


?>
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <script type="text/javascript" src="../plugin/tinymce/tinymce.min.js"></script>
    <title>Blog Post - Start Bootstrap Template</title>

    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/blog-post.css" rel="stylesheet">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
    

    <!-- Navigation -->
    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <div class="container">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="dashboard.php">Start Bootstrap</a>
            </div>
            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                    <li>
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">POSTING<b class="caret"></b></a>
                        <ul class="dropdown-menu">
                             <li><a href="posting.php">POST</a></li>
                             <li><a href="list.php">LIST POST</a></li>
                    
                        </ul>
                    </li>
                    
                </ul>
                <ul class="nav navbar-nav navbar-right">
                <li><a href="#" class="dropdown-toggle" data-toggle="dropdown">Hi, <?php echo strtoupper($username);?><b class="caret"></b></a>
                <ul class="dropdown-menu">
                    <li><a data-toggle="modal" href="#profile">PROFILE</a></li>
                    <li><a href="../proses/logout.php">LOGOUT</a></li>
                    
                </ul>
                </li>
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container -->
    </nav>
<?php
    require_once('../render.php');
    $render=new render;
    $render->profile($status, $username);
    ?>
    <!-- Page Content -->
    <div class="container">

        <div class="row">
        <div class="col-lg-8">

            <!-- Blog Post Content Column -->
            <script>
                    tinymce.init({
                        selector: "textarea#editor",
                        theme: "modern",
                        width: 500,
                        height: 300,
                        plugins: [
                             "advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
                             "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
                             "save table contextmenu directionality emoticons template paste textcolor responsivefilemanager"
                       ],
                       content_css: "css/content.css",
                       toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | l      ink image | print preview media fullpage | forecolor backcolor emoticons responsivefilemanager", 
                       style_formats: [
                            {title: 'Bold text', inline: 'b'},
                            {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
                            {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
                            {title: 'Example 1', inline: 'span', classes: 'example1'},
                            {title: 'Example 2', inline: 'span', classes: 'example2'},
                            {title: 'Table styles'},
                            {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
                        ],
                        external_filemanager_path:"/plugin/filemanager/",
                       filemanager_title:"Responsive Filemanager" ,
                       external_plugins: { "filemanager" : "/plugin/filemanager/plugin.min.js"}

                     });

                    </script>
                    <h3>POSTING</h3>
                
                <div class="">
                
                
                    <form class="form-horizontal"  action="../proses/updateposting.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
                        <input name="id" value="<?php echo $cek['idpost'] ?>" style="visibility:hidden;">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Judul Posting</label>
                            <div class="col-sm-9">
                                <input class="form-control" type="text" name="judul" placeholder="Judul Postingan" value="<?php echo $cek['judul']?>" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Pelajaran</label>
                            <div class="col-sm-9">
                            
                                <select class="form-control" type="text" name="mapel" placeholder="Kategori Mata Pelajaran" required>
                                        <option >--PILIH MAPEL--</option>
                            
                                <?php 
                                    $dbmpl=$cek['kategori'];
                                    $sql=mysql_query("SELECT * FROM mapel");
                                    while ($mpl=mysql_fetch_assoc($sql)) 
                                    {
                                        $mapel=$mpl['id'];
                                        $dbmpl=$cek['kategori'];
                                        if($dbmpl == $mapel)
                                        {
                                            echo"<option selected value='".$mpl['id']."'>".$mpl['mata_pelajaran']."</option>";
                                        }
                                        else
                                        {

                                     echo"<option value='".$mpl['id']."'>".$mpl['mata_pelajaran']."</option>";
                                        }
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Kelas</label>
                            <div class="col-sm-9">
                            
                                <select class="form-control" type="text" name="kls" placeholder="Masukkan Kelas" required />
                                    <option >--MASUKKAN KELAS--</option>;
                                    
                                    <?php
                                    
                                    $kls=mysql_query("SELECT * FROM kelas");
                                    while ($kelas=mysql_fetch_assoc($kls)) 
                                    {
                                        $klas=$kelas['id'];
                                        $dbkls=$cek['kelas'];

                                        if ($dbkls==$klas) 
                                        {
                                               echo "<option selected value='".$kelas['id']."'>".$kelas['kelas']."</option>";
                                        }
                                        else
                                        {
                                     echo "<option value='".$kelas['id']."'>".$kelas['kelas']."</option>";
                                        }
                                    }
                                    ?>
                                  </select> 
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">file</label>
                            <div class="col-sm-9">
                                <?php
                                $numrow=1; 
                                $id=$cek['idpost'];
                                $files=mysql_query("select nm_file from file where id_post=$id");
                                while($file=mysql_fetch_assoc($files))
                                {
                                    ?><input class="form-control" type="text" name="file<?php echo $numrow ?>" placeholder="pilih file" id="file<?php echo $numrow ?>" value="<?php echo $file['nm_file'] ?>">
                                          <a href="javascript:open_popup('../plugin/filemanager/dialog.php?type=2&popup=1&field_id=file<?php echo $numrow ?>')" class="btn iframe-btn btn-success" type="button" name="select<?php echo $numrow ?>">select</a><?php    
                                $numrow++;
                                }
                                while($numrow<=5)
                                {
                                    ?><input class="form-control" type="text" name="file<?php echo $numrow ?>" placeholder="pilih file" id="file<?php echo $numrow ?>">
                                          <a href="javascript:open_popup('../plugin/filemanager/dialog.php?type=2&popup=1&field_id=file<?php echo $numrow ?>')" class="btn iframe-btn btn-success" type="button" name="select<?php echo $numrow ?>">select</a><?php 
                                $numrow++;
                                }
                                ?>
                                
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Isi Postingan</label>
                            <div class="col-sm-10">
                                <textarea id="editor" name="area"><?php echo $cek['isi']?></textarea>
                            </div>
                        </div>
    
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <button class="btn btn-primary" type="submit" name="save" id="save">Publish</button>
                            </div>
                        </div>
                        </form>
                         
                </div>
              </div>
            <!-- Blog Sidebar Widgets Column -->
            <div class="col-md-4">

                <!-- Blog Search Well -->
                <div class="well">
                    <h4>Blog Search</h4>
                    <div class="input-group">
                        <input type="text" class="form-control">
                        <span class="input-group-btn">
                            <button class="btn btn-default" type="button">
                                <span class="glyphicon glyphicon-search"></span>
                        </button>
                        </span>
                    </div>
                    <!-- /.input-group -->
                </div>

                <!-- Blog Categories Well -->
                <div class="well">
                    <h4>Blog Categories</h4>
                    <div class="row">
                        <div class="col-lg-6">
                            <ul class="list-unstyled">
                                <?php 
                        $nm_kls=1;
                        $nm_mapel=100;
                        $querry1=mysql_query("SELECT distinct a.* from kelas a, posting b WHERE a.id = b.kelas");
                        while ($kls=mysql_fetch_assoc($querry1)) {
                        ?>
                        <li><a href="#<?php echo $nm_kls?>" class="dropdown-toggle" data-toggle="collapse"><?php echo $kls['kelas']?></a>
                            <ul id="<?php echo $nm_kls?>" class="collapse">
                                <?php
                                $klas=$kls['id'];
                                $query2=mysql_query("SELECT distinct a.* from mapel a, posting b WHERE a.id = b.kategori and b.kelas=$klas");
                                 while ($mapel=mysql_fetch_assoc($query2)) {
                                  
                                 ?>
                                <li><a href="#<?php echo $nm_mapel?>"  class="dropdown-toggle" data-toggle="collapse"><?php echo $mapel['mata_pelajaran']?></a>
                                    <ul id="<?php echo $nm_mapel?>" class="collapse">
                                      <?php
                                      $pelajaran=$mapel['id'];
                                      $query3=mysql_query("SELECT distinct a.* from guru a, posting b WHERE a.email=b.author and b.kelas='$klas' and b.kategori=$pelajaran ");
                                      while ($guru=mysql_fetch_assoc($query3)) 
                                        {?>
                                        <li><a href="search.php?email=<?php echo $guru['email'];?>" ><?php echo $guru['first_name']; echo' '; echo $guru['last_name'];?></a></li>
                                        <?php 
                                      }
                                        ?>
                                    </ul>
                                </li>
                                <?php
                                $nm_mapel++;
                                }?>
                            </ul>
                        </li>
                        <?php 
                        $nm_kls++;  
                        }
                        ?>
                            </ul>
                        </div>
                        
                    </div>
                    <!-- /.row -->
                </div>

                <!-- Side Widget Well -->
                <div class="well">
                    <h4>Side Widget Well</h4>
                    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Inventore, perspiciatis adipisci accusamus laudantium odit aliquam repellat tempore quos aspernatur vero.</p>
                </div>

            </div>

        </div>
        <!-- /.row -->

        <hr>

        <!-- Footer -->
        <footer>
            <div class="row">
                <div class="col-lg-12">
                    <p>Copyright &copy; Your Website 2014</p>
                </div>
            </div>
            <!-- /.row -->
        </footer>

    </div>
    <!-- /.container -->

    <!-- jQuery -->
    <script src="js/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>

<script src="../js/jquery.fancybox.pack.js"></script>
    <script type="text/javascript">
            function open_popup(url) {
                var w = 880;
                var h = 600;
                var l = Math.floor((screen.width-w)/2);
                var t = Math.floor((screen.height-h)/2);
                var win = window.open(url, 'ResponsiveFilemanager', "scrollbars=1,width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
            }
        </script>
</body>

</html>
